import request from "@/utils/request";
enum API {
  // 获取全部角色
  ALLROLE_URL = "/admin/acl/role/",
  // 新增角色
  ADDROLE_URL = "/admin/acl/role/save",
  // 修改角色
  UPDATE_URL = "/admin/acl/role/update",
  // 获取全部菜单与按钮
  ALLPERMISSION_URL = "/admin/acl/permission/toAssign/",
  // 分配权限
  SETPERMISSION_URL = "/admin/acl/permission/doAssign?",
  // 删除职位
  DELETEROLE_URL = "/admin/acl/role/remove/",
}

// 获取全部角色
export const reqAllRole = (page: number, limit: number, roleName: string) =>
  request.get<any, any>(
    API.ALLROLE_URL + `${page}/${limit}?roleName=${roleName}`
  );

// 添加或更新角色
export const reqAddOrUpdateRole = (data: any) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATE_URL, data);
  } else {
    return request.post<any, any>(API.ADDROLE_URL, data);
  }
};

// 获取全部菜单与按钮权限数据
export const reqAllMenuList = (roleId: number) => {
  return request.get<any, any>(API.ALLPERMISSION_URL + roleId);
};

// 分配权限
export const reqSetPermission = (roleId: number, permissionId: number[]) => {
  return request.post<any, any>(
    API.SETPERMISSION_URL + `roleId=${roleId}&permissionId=${permissionId}`
  );
};

// 删除职位
export const reqDeleteRole = (roleId: number) =>
  request.delete<any, any>(API.DELETEROLE_URL + roleId);
